$(function () {
    var rq = $.getRequest();
    $("#fsiteName1").text(rq.name);
    $("#fsiteName2").text(rq.name);

    setInterval(function () {
        updateTime();
    }, 1000);

    let userId = getStorage("loginUserId");
    updateDate(rq.id);

    updateAqifor24(rq.id, "chartAqi24");
    //联网率
    updateDeviceStatus(rq.id, "chartDevice");
});

function getAqiIndex(aqi) {
    var index = 0;
    if (aqi <= 1) {
        index = 0;
    } else if (aqi <= 2) {
        index = 1;
    } else if (aqi <= 3) {
        index = 2;
    } else if (aqi <= 4) {
        index = 3;
    } else if (aqi <= 5) {
        index = 4;
    } else {
        index = 5;
    }
    return index;
};


 

function updateDate(id) {
    let mapSrc = `../images/003/indoor/${id}.png`;
    // let mapSrc = `images/indoor/${id}.png`;
    api.getDataIndoor(id, function (d) {
        // reloadTable();
        var ps = new Array();
        // d.map(function (item) {
        //     ps.push({
        //         id: item.fpointNo,
        //         name: item.fpointName,
        //         width: item.fpointW,
        //         heigth: item.fpointH,
        //         left: item.fpointD,
        //         top: item.fpointL
        //     });
        // });
    });
}

function reloadTable(data) {
    data.filter(item => {
        if(item.fmoniterCo2===0 || item.fmoniterCo2==='0.000' || item.fmoniterCo2=== null){
          item.fmoniterCo2=0
        }
        if(item.fmoniterJq===0 || item.fmoniterJq==='0.000' || item.fmoniterJq=== null){
          item.fmoniterJq=0
        }
        if(item.fmoniterYjw===0 || item.fmoniterYjw==='0.000' || item.fmoniterYjw=== null){
          item.fmoniterYjw=0
        }
    } )
    var $tr = $("#myTemplate").tmpl(data);
        let $tbody = $("#tbody");
        $tbody.empty();
        $tr.appendTo($tbody);
}
//更新时间
function updateTime() {
    var $timewarper = $('.time-content', '#time');
    if ($timewarper.length <= 0) {
        $timewarper = $("<span class='time-content'></span>");
        $("#time").prepend($timewarper);
    }
    var t = $.getTime();
    var time = t.y + "-" + t.m + "-" + t.d + "   星期" + t.w + "   " + t.h + ":" + t.M + ":" + t.s;
    $timewarper.html(time);
}